//初始化模态框;
function initModal(id, content, isDouble, isSingle) {
	var mId = id || "myModal";
	var mContent = content || "这里是内容";
	var doubleBtn = isDouble;
	var failBtn = isSingle;
	var obj = $("<div>");
	var oBtn = $("<button>");
	
	var winH = $(window).height();
//	var marT = (winH-150)/2;
	
	var dialog = obj.clone().addClass("modal modal-tahoe dialog-tahoe").attr("tabindex", -1).attr("id", mId);
	var mdDialog = obj.clone().addClass("modal-dialog modal-sm");
//	mdDialog.css("margin-top", marT);
	var mcDialog = obj.clone().addClass("modal-content");
		
	//modal-footer;	
	var mfoot = obj.clone().addClass("modal-footer tc");
	var ofBtn1 = oBtn.clone().addClass("btn").attr({
		"data-dismiss": "modal",
		"yesBtn": "true"
	}).html("确定");
	var ofBtn2 = oBtn.clone().addClass("btn btn-dismiss").attr({
		"data-dismiss": "modal",
		"noBtn": "true"
	}).html("取消");
	var titleInfo="";
	if(doubleBtn) {
		mfoot.append(ofBtn1, ofBtn2);
		titleInfo="确认框";
	} else {
		mfoot.append(ofBtn1);
		titleInfo="提示框";
	}
	if (failBtn) {
		mfoot.append(ofBtn1);
		titleInfo = "提示框";
	}
	//modal-body icon icon-error
	// var infoIcon=$("<i class='glyphicon glyphicon-info-sign'></i>");
	// var infoIcon2 = $("<i class='icon icon-success'></i>");
	// var infoIcon3 = $("<i class='icon icon-close colorGrey'></i>");
	var mbodyInfo = $("<p/>").addClass("inline_block").html(mContent);
	var mbody = obj.clone().addClass("modal-body tc pt25").append(mbodyInfo);
	// if(doubleBtn){
	// 	var mbody = obj.clone().addClass("modal-body tc pt25").append(infoIcon,mbodyInfo);
	// }else{
	// 	var mbody = obj.clone().addClass("modal-body tc pt25").append(infoIcon2,mbodyInfo);
	// }
	// if (failBtn) {
	// 	var mbody = obj.clone().addClass("modal-body tc pt25").append(infoIcon3, mbodyInfo);
	// }
	//modal-header
	var closeBtn=$("<button type='button'/>").addClass("close icon icon-close").attr("data-dismiss","modal");
	var mtitle=$("<h5/>").addClass("modal-title").html(titleInfo);
	var mhead=obj.clone().addClass("modal-header").append(closeBtn,mtitle);

	mcDialog.append(mhead,mbody,mfoot).appendTo(mdDialog);
	mdDialog.append(mcDialog);
	dialog.append(mdDialog);
	$("body").append(dialog);
	return dialog;
}

/*
 * 作用： 信息模态框；（一个按钮  确认）
 * 参数 : mid   弹框ID; 
 * 参数：msg：展示信息；
 * 参数：callback：点击确认后的回调函数；
 *
 */

function showAlertDialog(options) {
	var id =options.mid||"modal_00";
	var content =options.msg||"";
	var dialog = initModal(id, content, false);
	var yesBtn = $(dialog).find("button[yesBtn=true]");
	$(yesBtn).click(function() {
		$(dialog).modal('hide').remove();
		if(options.callback) {
			options.callback();
		}
	})
	$(dialog).modal({
		backdrop: "static"
	});
}

function showAlertDialogFS(options) {
	var id = options.mid || "modal_00";
	var content = options.msg || "";
	var dialog = initModal(id, content, false, true);
	var yesBtn = $(dialog).find("button[yesBtn=true]");
	$(yesBtn).click(function () {
		$(dialog).modal('hide').remove();
		if (options.callback) {
			options.callback();
		}
	})
	$(dialog).modal({
		backdrop: "static"
	});
}
/*
 * 作用： 确认信息模态框；（两个按钮 确认/取消）
 * 参数 : mid   弹框ID; 
 * 参数：msg  展示信息；
 * 参数：callback 点击确认后的回调函数；
 */
function showConfirmDialog(options) {
	var id =options.modalId ||"modal_00";
	var content =options.msg|| "默认信息";
	var dialog = initModal(id, content, true);
	var yesBtn = $(dialog).find("button[yesBtn=true]");
	var noBtn = $(dialog).find("button[noBtn=true]");

	$(yesBtn).click(function() {
		$(dialog).modal('hide').remove();
		if(options.callback) {
			options.callback(true);
		}
	})
	$(noBtn).click(function() {
		$(dialog).modal('hide').remove();
		if(options.callback) {
			options.callback(false);
		}
	})
	/*此处可以配置参数，详情见 bootstrap 中的modal.js */
	/*backdrop:static ==>鼠标点击弹出框之外的地方，弹出框不消失；*/
	$(dialog).modal({
		backdrop: "static"
	});
}
//这是confirm的回调函数示例;
function confirmCallback(flag) {
	if(flag) {
		console.log("yesBtn")
	} else if(!flag) {
		console.log("noBtn")
	}
}